home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / demos / audio / synthia / midif.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  3.3 KB  |  149 lines

  1. /*
  2.  * Copyright 1991, 1992, 1993, 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. /*
  18.  * Copyright (C) 1991, Silicon Graphics, Inc.
  19.  * All Rights Reserved.
  20.  */
  21.  
  22.     /*
  23.      *  midif  -  MIDI file format definitions
  24.      *
  25.      *  Jim Bennett
  26.      *  1991
  27.      */
  28.  
  29. #define    INSTRUMENTS    16        /* Number of instruments    */
  30. #define    MAX_VOICES    32        /* Maximum number of voices    */
  31.  
  32. #define    WFTABL        720    /* Length of waveform tables        */
  33. #define    WF_REPLICATION     30    /* Replication factor for waveform    */
  34.  
  35. #define    MIDDLE_C    60
  36. #define    A_ABOVE        (MIDDLE_C+9)
  37. #define    A_HZ        440
  38.  
  39. #define    SYNTHIA_RATE    AL_RATE_32000
  40. #define    SAMPLE_BUFSIZE    (SYNTHIA_RATE/10)
  41.  
  42. #define    MF_header    "MThd"
  43. #define    MF_track    "MTrk"
  44.  
  45. struct    s_mfhd
  46.     {
  47.     int    format;
  48.     int    ntrks;
  49.     int    division;
  50.     };
  51.  
  52.     /*
  53.      *  MIDI event structure:  time (in seconds) and event code
  54.      *
  55.      *  The 32-bit event code is structured as follows:
  56.      *    bits  0- 7:    pitch
  57.      *    bits  8-15:    velocity
  58.      *    bits 16-23:    event code (note on or off)
  59.      *    bits 24-27:    program
  60.      *    bits 28-31:    finger
  61.      */
  62.  
  63. struct    s_mfevent
  64.     {
  65.     float    time;
  66.     long    event;
  67.     };
  68.  
  69. #define    END_TIME    1.0e+30
  70. #define    LONG_TIME    1.0e+20
  71.  
  72.     /*
  73.      *  MIDI file events
  74.      */
  75.  
  76. #define    META_EVENT    0xff
  77. #define    SYSEX_EVENT    0xf0
  78. #define    SYSEX_EVENTA    0xf7
  79.  
  80.     /*
  81.      *  META event types
  82.      */
  83.  
  84. #define    END_TRACK    0x2f
  85.  
  86.     /*
  87.      *  MIDI status bytes
  88.      */
  89.  
  90. #define    NOTE_OFF    0x80
  91. #define    NOTE_ON        0x90
  92. #define    KEY_PRESSURE    0xa0
  93. #define    PARAMETER    0xb0
  94. #define    PROGRAM        0xc0
  95. #define    CHAN_PRESSURE    0xd0
  96. #define    PITCH_WHEEL    0xe0
  97.  
  98.     /*
  99.      *  Per track structure for playing tracks
  100.      */
  101.  
  102. #define    MAX_TRACKS    32        /* Maximum number of tracks    */
  103. #define    MAX_FINGERS    16        /* Maximum fingers per track    */
  104.  
  105.     /*
  106.      *  First must define per finger structure
  107.      */
  108.  
  109. struct    s_finger
  110.     {
  111.     struct s_voice *vp;    /* Voice pointer        */
  112.     int    note;        /* Pitch of current note    */
  113.     int    wl;        /* Wavelength of current tone    */
  114.     float    wlis;        /* Wavelength index scale    */
  115.     float    atten;        /* Waveform attenuation        */
  116.     float    catten;        /* Complement of above        */
  117.  
  118.     float    *aeptr;        /* Amplitude envelope pointer    */
  119.     int    wli;        /* Wavelength index        */
  120.     float    t;        /* Time into amplitude envelope    */
  121.     float    val;        /* Current value of amplitude    */
  122.     float    vdel;        /* Current amplitude delta    */
  123.  
  124.     int    finger;        /* Finger number        */
  125.     int    track;        /* Track for this finger    */
  126.     float    *wftab;        /* Waveform table        */
  127.     };
  128.  
  129. struct    s_ptrk
  130.     {
  131.     struct s_mfevent *base;        /* This track's events        */
  132.     struct s_mfevent *evptr;
  133.     float        *on_amp_env;    /* Amplitude envelope/keydown    */
  134.     float        *off_amp_env;    /* Amplitude envelope/keyup    */
  135.     int        nfingers;    /* Max number of fingers    */
  136.     struct s_finger f[2*MAX_FINGERS]; /* Finger state for this track */
  137.     };
  138.  
  139.     /*
  140.      *  Currently active voice structure
  141.      */
  142.  
  143. struct    s_voice
  144.     {
  145.     struct    s_finger *fp;
  146.     int    keydown;
  147.     struct s_voice *next;
  148.     };
  149.